#include <iostream>
#include <jsoncpp/json/json.h>
#include <string>
#include <fstream>

using namespace std;

struct stu
{
    string name;
    int age;
    double weight;

    void Debug()
    {
        cout << name << endl;
        cout << age << endl;
        cout << weight << endl;
    }
};

int main()
{
    ifstream in("out.txt");
    if(!in.is_open()) return 1;
    char buffer[1024];
    in.read(buffer, sizeof(buffer));
    in.close();

    // 反序列化
    string json_string = buffer;
    Json::Value root;
    Json::Reader reader;
    bool res = reader.parse(json_string, root);
    (void)res;

    struct stu zs;
    zs.name = root["name"].asString();
    zs.age = root["age"].asInt();
    zs.weight = root["weight"].asDouble();

    zs.Debug();

    return 0;
}

// int main()
// {
//     // 结构化数据
//     struct stu zs = {"张三", 18, 72};

//     // 转换为字符串
//     Json::Value root;
//     root["name"] = zs.name;
//     root["age"] = zs.age;
//     root["weight"] = zs.weight;

//     //Json::FastWriter writer;
//     Json::StyledWriter writer;
//     string str = writer.write(root);

//     ofstream out("out.txt");
//     if(!out.is_open())
//     {
//         cout << str;
//         return 1;
//     }
//     out << str;
//     out.close();
    
//     return 0;
// }